﻿using System.Diagnostics;

namespace GmailChecker.Utils
{
    static class App
    {
        public static volatile bool WaitDialogResult = false;        

        public static bool IsUserInstanceExist()
        {
            bool isExist = false;

            Process curProc = Process.GetCurrentProcess();

            Process[] pp = Process.GetProcessesByName(curProc.ProcessName);

            if (pp.Length > 1)
            {
                int i = 0;
                foreach (Process p in pp)
                {
                    if (p.SessionId == curProc.SessionId)
                        i++;
                }

                if (i > 1)
                    isExist = true;
            }

            curProc.Dispose();
            foreach (Process p in pp)
            {
                p.Dispose();
            }            

            return isExist;  
        }
    }
}
